import React, { useState } from 'react'

export default function App() {
    let [username, setUsername] = useState('atguigu');
    let [pwd, setPwd] = useState('123123')
    const submitHandler = (e)=>{
        e.preventDefault();
        console.log('username:' , username);
        console.log('pwd: ', pwd);
    }
    // const changeUsername = (e)=>{
    //     setUsername(e.target.value);
    // }
    // const changePwd = (e)=>{
    //     setPwd(e.target.value);
    // }

    // const change = (e, fn)=>{
    //     fn(e.target.value);
    // }

    const change = function(fn){
        return function(e){
            fn(e.target.value)
        }
    }
    return (
        <>
            <form onSubmit={submitHandler}>
                {/* <p>用户名: <input type="text" onChange={(e)=>change(e,setUsername)} name="username" value={username} /></p>
                <p>密码: <input type="text" name="pwd" value={pwd} onChange={(e)=>change(e,setPwd)}/></p> */}
                
                <p>用户名: <input type="text" onChange={change(setUsername)} name="username" value={username} /></p>
                <p>密码: <input type="text" name="pwd" value={pwd} onChange={change(setPwd)}/></p>
                <p><button>保存</button></p>
            </form>
        </>
    )
}
